package com.pr.entity;

/**
 * @description:
 * @projectName:spring-skill
 * @see:com.pr.entity
 * @author:LXC
 * @createTime:2024/6/19 09:54
 * @version:1.0
 */
public class SynchronizedExample {

    public static void main(String[] args) {
        Account account = new Account(100);

        Runnable runnable = () -> {
            for (int i = 0; i < 100; i++) {
                account.withdraw(1);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };

        Thread thread1 = new Thread(runnable, "Thread-1");
        Thread thread2 = new Thread(runnable, "Thread-2");

        thread1.start();
        thread2.start();
    }
}
